package com.cwj.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author chenwujie
 * @date 2021-01-25 16:33
 */
public class SleepTest {
    private static volatile int n;
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                n++;
//                synchronized (SleepTest.class){
//                }
            }
        };
        Thread thread = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        Thread thread3 = new Thread(runnable);
        thread.start();
        thread2.start();
        thread3.start();
        Thread.sleep(3000);
        System.out.println(n);
    }
}
